package org.zjx.task.core;

import org.zjx.context.ChainContext;
import org.zjx.task.exception.TaskExecutionException;

import java.util.Map;

public interface ITask {
    enum ExecutionStrategy {
        SYNC,   // 同步执行
        ASYNC,  // 异步执行
        AUTO    // 自动选择
    }

    enum TaskStatus {
        PENDING,        // 等待执行
        RUNNING,        // 执行中
        SUCCESS,        // 执行成功
        FAILED,         // 执行失败
        INTERRUPTED,    // 被中断
        RETRYING        // 重试中
    }

    enum FailureStrategy {
        CONTINUE,   // 继续执行后续任务
        STOP,   // 停止所有任务
        RESTART,    // 重启当前任务
        FALLBACK // 回退
    }

    String getTaskId();

    void initialize();


    Map<String,Object> getParams();
    void setParams(Map<String,Object> params);

    void execute(ChainContext context, TaskScheduler scheduler) throws Exception;

    void run(ChainContext context,TaskScheduler scheduler) throws TaskExecutionException;

    TaskStatus getStatus();

    void setStatus(TaskStatus status);

    default FailureStrategy getFailureStrategy() {
        return FailureStrategy.STOP;
    }

    void setFailureStrategy(FailureStrategy failureStrategy);

    default ExecutionStrategy getExecutionStrategy() {
        return ExecutionStrategy.AUTO;
    }

    void setExecutionStrategy(ExecutionStrategy executionStrategy);

    boolean isAsyncSupported();
}
